<?php
namespace app\admin\model;
use think\Model;
use think\Db;
use QRcode;
class agentModel extends Model{
    public function QRCODE($id){
        $fileimg = "./static/theme/img/agentcode/agentrqcode{$id}.png";
        if(!file_exists($fileimg)){
            require_once APP_PATH.'/common/WxpayApi/example/phpqrcode/phpqrcode.php';
            $value = "http://api.zgzdtx.com/zdRegister/register.html?agent_id={$id}";         //二维码内容
            $errorCorrectionLevel = 'L';  //容错级别
            $matrixPointSize = 5;      //生成图片大小
            //生成二维码图片
            $filename = $fileimg;
            QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, 2);
            $QR = $filename;        //已经生成的原始二维码图片文件
            $QR = imagecreatefromstring(file_get_contents($QR));
            //输出图片
            imagepng($QR, $fileimg);
            imagedestroy($QR);
        }
        return "/static/theme/img/agentcode/agentrqcode{$id}.png";
    }
}